package com.ymatou.iapi.godmch.testcase;

import java.time.LocalDateTime;
import java.util.List;

import oracle.net.aso.i;

import org.apache.ibatis.session.RowBounds;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.getPointDetailListBean;
import com.ymatou.iapi.godmch.service.getPointDetailListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.godmch.point_change_detail;
import com.ymttest.database.model.godmch.point_change_detailExample;
import com.ymttest.database.sqlwapper.godmch.point_change_detailWapper;
import com.ymttest.utils.EnvSetup;
/**
*获取积分明细列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getPointDetailList{
	private static getPointDetailListBean bean;
	private static getPointDetailListCall call;
	Integer agent_promote_mchId=Integer.parseInt(EnvSetup.getData("agent_promote_mchId"));
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取积分明细列表");
	}

	@Before
	public void caseUp() {
		bean=new getPointDetailListBean();
		call=new getPointDetailListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getPointDetailList_001() {
		Logger.start(true,"获取积分明细列表-主商户");
		try {
            
			bean.setMchId(agent_promote_mchId);
			bean.setPageIndex(1);
			bean.setPageSize(10);
			//bean.setBeginTime(LocalDateTime.now().plusDays(0));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证statusCode");
			JSONArray return_jArray=call.getDetailList();
			point_change_detailWapper detailWapper=new point_change_detailWapper();
			
			point_change_detailExample example=new point_change_detailExample();
			example.createCriteria().andPlatform_mch_idEqualTo(bean.getMchId());
			example.setOrderByClause(" create_Time desc ");
			 
			List<point_change_detail>  DB_details=detailWapper.selectByExample(example);
			Logger.verifyEquals(DB_details.size(), call.getTotal(), "验证Total");
			for(int i=0;i<return_jArray.length();i++)
			{
				JSONObject jObject=new JSONObject(return_jArray.get(i).toString());
				point_change_detail DB_detail=DB_details.get(i);
				Logger.verifyEquals(DB_detail.getUser_id(),jObject.getInt("userId"), "验证userId");
			}
			
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}